package com.example.onlinetaxi.util.OKHttpUtil;

import android.util.Log;

import com.example.onlinetaxi.dto.DataRequest;
import com.google.gson.Gson;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class RequestUtil {
    // 对请求编码方式进行设置
    public static final MediaType FORM_CONTENT_TYPE
            = MediaType.parse("application/json; charset=utf-8");

    public static RequestBody getRequestBody(Map<String, String> map) {
        StringBuffer sb = new StringBuffer();
        //设置表单参数
        DataRequest dataRequest = new DataRequest();
        dataRequest.setData(map);
        // 使用Gson对参数进行转换
        Gson gson = new Gson();
        sb.append(gson.toJson(dataRequest));

//        for (String key: map.keySet()) {
//            sb.append(key+"="+map.get(key)+"&");
//        }
        Log.i("TAG", "" + sb.toString());

        return RequestBody.create(FORM_CONTENT_TYPE, sb.toString());
    }
}
